/**
 * %SVN.HEADER%
 * 
 * based on work by Simon Levy
 * http://www.cs.wlu.edu/~levy/software/kd/
 */
package vn.com.epi.algorithm.kdtree;

// Hyper-Point class supporting KDTree class

class HPoint {

    protected int[] coord;

    protected HPoint(int n) {
        coord = new int[n];
    }

    protected HPoint(int[] x) {

        coord = new int[x.length];
        for (int i = 0; i < x.length; ++i)
            coord[i] = x[i];
    }

    protected Object clone() {

        return new HPoint(coord);
    }

    protected boolean equals(HPoint p) {

        // seems faster than java.util.Arrays.equals(), which is not
        // currently supported by Matlab anyway
        for (int i = 0; i < coord.length; ++i)
            if (coord[i] != p.coord[i])
                return false;

        return true;
    }
        
    protected static double sqrdist(HPoint x, HPoint y) {
    	double dist = eucdist(x, y);
        return dist * dist;
    }
    
    protected static double eucdist(HPoint x, HPoint y) {
    	double total  = 0;
    	double common = 0;

        for (int i = 0; i < x.coord.length; ++i) {
        	total += x.coord[i] + y.coord[i];
        	common += Math.min(x.coord[i], y.coord[i]);
        }

        return 10000 - common/(total - common);
    }

    public String toString() {
        String s = "";
        for (int i = 0; i < coord.length; ++i) {
            s = s + coord[i] + " ";
        }
        return s;
    }

}
